﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC3Demo.Controllers
{
   public class HomeController : Controller
   {
      public ActionResult Index()
      {
         ViewBag.Message = "欢迎访问知识库!";

         ViewData["RecentArticles"] = KnowledgeEntity.Article.GetArticleRecently(5);
         //ViewData["RecentArticles"] = GetRecentArticlesMock(5);

         return View();
      }

      [NonAction]
      private Dictionary<int, KnowledgeEntity.Article> GetRecentArticlesMock(int count)
      {
         Dictionary<int, KnowledgeEntity.Article> recentArticles = new Dictionary<int, KnowledgeEntity.Article>();
         recentArticles.Add(1, new KnowledgeEntity.Article
         {
            ArticleID = 1,
            Title = @"1.Title of First Article",
            Content = @"1.Content of First Article"
         });
         recentArticles.Add(2, new KnowledgeEntity.Article
         {
            ArticleID = 2,
            Title = @"2.Title of Second Article",
            Content = @"3.Content of Second Article"
         });

         return recentArticles;
      }

      public ActionResult CheckConnection()
      {
         ViewBag.Message = "本知识是基于ASP.NET MVC 3开发框架编写的!";

         if (DBHelper.SqlHelper.TestConnection())
            ViewData["ConnectionCheckResult"] = "数据库连接成功!";
         else
            ViewData["ConnectionCheckResult"] = "数据库连接失败!";

         return View("Index");
      }

      public ActionResult About()
      {
         return View();
      }
   }
}
